package com.ruoyi.galaxy.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.galaxy.domain.GalaxyUser;
import com.ruoyi.galaxy.mapper.GalaxyUserMapper;
import com.ruoyi.galaxy.service.IGalaxyUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yeoman
 * @date 2025/4/10 12:55
 * @description 银河票务用户服务实现类
 */
@Component
public class GalaxyUserServiceImpl implements IGalaxyUserService {

    @Resource
    private GalaxyUserMapper galaxyUserMapper;

    @Override
    public List<GalaxyUser> selectUserList(GalaxyUser user) {
        return galaxyUserMapper.selectUserList(user);
    }

    @Override
    public boolean checkUserAccountUnique(GalaxyUser user) {
        Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
        GalaxyUser galaxyUser = galaxyUserMapper.checkUserAccountUnique(user);
        if (StringUtils.isNotNull(galaxyUser) && galaxyUser.getUserId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public int insertUser(GalaxyUser user) {
        return galaxyUserMapper.insertUser(user);
    }

    @Override
    public GalaxyUser selectUserById(Long userId) {
        return galaxyUserMapper.selectUserById(userId);
    }

    @Override
    public List<GalaxyUser> selectUserAll() {
        return galaxyUserMapper.selectUserAll();
    }

    @Override
    public int updateUser(GalaxyUser user) {
        return galaxyUserMapper.updateUser(user);
    }

    @Override
    public void deleteUserByIds(String ids) {
        Long[] userIds = Convert.toLongArray(ids);
        for (Long userId : userIds) {
            galaxyUserMapper.deleteUserById(userId);
        }
    }
}
